/* model */
import RootWindowInitData from '@model/interface/initData/RootWindowInitData'
import LoginUser from '@model/entity/LoginUser/LoginUser'
/* use */
import { useEnv } from '@hooks/useEnv'
/* util */
import { getRootWindowInitData } from '@src/util/window'
/* vue */
import { computed, ComputedRef } from 'vue'

const rootWindowInitData = getRootWindowInitData()

export function useRootWindowInitData(): ComputedRef<RootWindowInitData> {
  return computed(() => rootWindowInitData)
}

export function useTenantId(): ComputedRef<string> {
  const { isDev } = useEnv()
  const defaultTenantId = isDev ? '' : ''
  
  return computed(() => rootWindowInitData?.user?.tenantId || defaultTenantId)
}

export function useRootUser(): ComputedRef<LoginUser> {
  const defaultUser = {}
  return computed(() => rootWindowInitData?.user || defaultUser)
}
